package org.frame.myaop;

import java.util.ArrayList;
import java.util.List;

public class InterceptorChain implements IAddFeatureChain {

    public List<Inteceptor> before;
    public List<Inteceptor>after;

    public InterceptorChain() {
        before = new ArrayList<>();
        after = new ArrayList<>();
    }

    public void addBefore(Inteceptor e){
        before.add(e);
    }
    public void addAfter(Inteceptor e){
        after.add(e);
    }
    @Override
    public void beforeExecute() {
        for (Inteceptor inteceptor : before) {
            inteceptor.execute();
        }
    }

    @Override
    public void afterExecute() {
        for (Inteceptor inteceptor : after) {
            inteceptor.execute();
        }
    }
}
